const { Transform } = require('stream');
const utils = require('../../utils');

module.exports = function (ms = 1000) {
  const stream = new Transform({ objectMode: true });
  stream._transform = async function (chunk, encoding, callback) {
    await utils.sleep(ms);
    stream.push(chunk);
    callback();
  };

  stream.on('finish', function () {
    utils.debug('waitTransform [finish]');
  });

  return stream;
};